﻿# 调用chatmodels，以OpenAI为例
import os

from dotenv import load_dotenv
from langchain.chat_models import ChatOpenAI
from langchain.schema.messages import HumanMessage, AIMessage

load_dotenv("../ai.env")

api_base = os.getenv("OPENAI_API_BASE")
api_key = os.getenv("OPENAI_KEY")

chat = ChatOpenAI(
    model="gpt-4",
    temperature=0,
    openai_api_key=api_key,
    openai_api_base=api_base
)

messages = [
    AIMessage(role="system", content="你好，我是tomie！"),
    HumanMessage(role="user", content="你好tomie，我是狗剩！"),
    AIMessage(role="system", content="认识你很高兴！"),
    HumanMessage(role="user", content="你知道我叫什么吗？")
]
response = chat.invoke(messages)
print(response)
